<script setup>

import moduleJson from "@/components/page/moduleJson"
import dataJson from "@/components/page/dataJson"
import {inject, onMounted, ref} from "vue";
import ModelService from "@/service/impl/ModelService.js";
import ModelList from "@/model/ModelList.js";
import SentenceConfig from "@/components/language/SentenceConfig.vue";
import dialogJson from "@/components/dialog/dialogJson.js";
import ClassificationService from "@/service/impl/ClassificationService.js";
import Dialog from "@/components/dialog/Dialog.vue";
import QAService from "@/service/impl/QAService.js";

const sentenceConfigDialog = dialogJson()
const t = inject('$t')
const message = inject('message')
const data = dataJson()
const module = moduleJson()
const modelList = ref(new ModelList())
const currentData = ref(null)
const testTrainingDialog = dialogJson()

onMounted(() => {
    module.value.page.show = true
    module.value.init(null, null,
        ModelService.url.modelDel, null, null)
    module.value.operations.width = "200px"
    module.value.dialog.width = "40%"
    init()
})


const init = () => {
    module.value.dialog.show = false
    modelList.value.modelType = 2
    data.value.data = modelList.value
    ModelService.modelList(data.value.source()).then(res => {
        data.value.init(res)
    })
}

const training = (row) => {
    sentenceConfigDialog.value.show = true
    sentenceConfigDialog.value.title = "设置参数"
    sentenceConfigDialog.value.width = "40%"
    row.data.modelConfig.remark = row.data.remark
    sentenceConfigDialog.value.data = row.data.modelConfig
    currentData.value = row.data
}


const delConfirm = (obj) => {
    ModelService.modelDel(obj).then(res => {
        init()
    })
}

const onTraining = () => {

}

const testTraining = () => {
    testTrainingDialog.value.title = '测试样本'
    testTrainingDialog.value.width = '40%'
    testTrainingDialog.value.show = true
    testTrainingDialog.value.data = {
        str : '',
        json : ''
    }
}

const onTest = () => {
    if(!testTrainingDialog.value.data?.str){
        return
    }
    testTrainingDialog.value.data.str = testTrainingDialog.value.data.str.trim()
    QAService.qaTestTraining(testTrainingDialog.value.data.str)
        .then(res => {
            testTrainingDialog.value.data.json = res.data
        })
}


</script>
<template>
    <Page
        @refresh="init"
        :data="data"
        :module="module"
        @del-confirm="delConfirm"
        @page-current-change="init"
        @page-size-change="init"
    >
        <template #table-left>
        </template>
        <template #operate-before>
            <el-button type="primary" @click="testTraining">测试</el-button>
        </template>
        <template #table-column>
            <el-table-column type="selection" width="55"/>
            <el-table-column prop="remark" label="备注"/>
            <el-table-column prop="userName" label="操作人"/>
            <el-table-column prop="createTime" label="创建时间"/>
        </template>
        <template #after-table-event="row">
<!--            <el-button type="primary" @click="training(row)">微调</el-button>-->
        </template>
        <template #table-dialog>
        </template>
        <template #table-search>

        </template>
    </Page>

    <Dialog :dialog="testTrainingDialog" >
        <el-row class="test-training">
            <el-row class="test-training-top">
                <pre>{{testTrainingDialog.data.json}}</pre>
            </el-row>
            <el-row class="test-training-bottom">
                <el-input
                    v-model="testTrainingDialog.data.str"
                    style="width: 100%;height: 100%"
                    resize="none"
                    type="textarea"
                    placeholder="请输入内容"
                />
            </el-row>
        </el-row>
        <template #table-dialog-btn>
            <el-button type="primary" @click="onTest">测试</el-button>
        </template>
    </Dialog>

<!--    <SentenceConfig :sentence-config-dialog="sentenceConfigDialog" :fineTune="true" @on-training="onTraining"/>-->

</template>

<style lang="scss" scoped>
.test-training{
    height: 300px;
    width: 100%;
}
.test-training-top{
    height: 240px;
    width: 100%;
    overflow-y: auto;
}
.test-training-bottom{
    width: 100%;
    height: auto;
}
</style>
